#ifndef __BRANCH1_BASE_BULLET_MANAGER_H__
#define __BRANCH1_BASE_BULLET_MANAGER_H__
#include "Branch1BaseConfig.h"
#include <ogre/Ogre.h>
#include <daisy/Singleton.h>
#include <daisy/EventSystem.h>
#include "OgreNewt.h"
#include <boost/pool/object_pool.hpp>
namespace Branch1
{
	namespace Bullet
	{
		class _BranchBaseExport Bullet
		{
		public:
			Bullet();
			~Bullet();
			void addTime(Ogre::Real interval);
			void setDisppearInterval(Ogre::Real disappearInterval);
			void setPositionAndOrientation(Ogre::Vector3& position, Ogre::Quaternion& orientation);
			//fire
			void fire(Ogre::Vector3& position,Ogre::Vector3& power);
			
			void setRemove();
			//init whole class resource

			bool isRemove();
			static void init();
			static OgreNewt::MaterialID* getMaterialID();
			//release whole class resource
			static void shutdown();
		private:
			Ogre::SceneNode* _node;
			OgreNewt::Body* _physicsBody;
			OgreNewt::MaterialID* _materialID;
			Ogre::Entity* _entity;

			Ogre::Real _timeLine;
			Ogre::Real _disappearInterval;
			bool _isRemove;
			
			static Ogre::SceneManager* _sceneMgr;
			static OgreNewt::World* _pysicsWorld;
			static OgreNewt::MaterialID* _materialID;
			
		};
		typedef boost::shared_ptr<Bullet> BulletPtr;

		class _BranchBaseExport BulletFactory:public DAISY::Tools::Singleton<BulletFactory>
		{
		public:
			BulletFactory();
			~BulletFactory();
			
			//create bullet
			Bullet* createBullet(Ogre::Vector3& position, Ogre::Quaternion& orientation,Ogre::Real disappearInterval);
			
			//destroy bullet
			void destroyBullet(Bullet* bullet);
		private:
			boost::object_pool<Bullet> _bulletPool;

		};

		class _BranchBaseExport BulletManager:public DAISY::Tools::Singleton<BulletManager>,public DAISY::EventHandler
		{
		public:
			BulletManager();
			~BulletManager();
			void setDisapearInterval(Ogre::Real time);
			void Fire(Ogre::Vector3& position,Ogre::Quaternion& orient,Ogre::Vector3& power,int number = 1);
			void removeFromList(Bullet* bullet);
		private:
			void doEnable();
			void doExecute(DAISY::Event * evt);
			void doDisable();

			std::list<Bullet*> _bulletList;
			Ogre::Real _disppearInterval;
			Ogre::Real _lastTime;
			Ogre::Real _currTime;
			Ogre::Real _timeSinceLastFrame;
			Ogre::Timer* _timer;

		};
	}
}
#endif